class Solution {
    public:
    /**
	* 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
	*
	* 判断岛屿数量
	* @param grid char字符型vector<vector<>>
	* @return int整型
	*/
    int m = 0, n = 0;
    int dx[4] = {0, 0, -1, 1};
    int dy[4] = {1, -1, 0, 0};
    int solve(vector<vector<char> >& grid) {
        m = grid.size(), n = grid[0].size();
        int ret = 0;
        for(int i = 0; i < m; ++i)
        {
            for(int j = 0; j < n; ++j)
            {
                if(grid[i][j] == '1')
                {
                    ++ret;
                    dfs(grid, i, j); // 在原数组把相邻的1变为0
                }
            }
        }
        return ret;
    }
    void dfs(vector<vector<char> >& grid, int sr, int sc)
    {
        grid[sr][sc] = '0';
        for(int i = 0; i < 4; ++i)
        {
            int x = sr + dx[i], y = sc + dy[i];
            if(x >= 0 && x < m && y >= 0 && y < n && grid[x][y] == '1')
            {
                dfs(grid, x, y);
            }
        }
    }
};